/**
* Created with IntelliJ IDEA.
* Description:
* User:DELL
* Date:2025-07-12
* Time:23:08
*/
public class Demo11 {
    int[] dx={0,0,-1,1};
    int[] dy ={-1,1,0,0};
    public int[][] highestPeak(int[][] isWater) {
        int m=isWater.length,n=isWater[0].length;
        int[][] dist =new int[m][n];
        //初始化
        for(int i=0;i<m;i++){
            for(int j=0;j<n;j++){
                dist[i][j]=-1;
            }
        }
        Queue<int[]> q =new LinkedList<>();
        //把原点加入到对列中
        for(int i=0;i<m;i++){
            for(int j=0;j<n;j++){
                if(isWater[i][j]==1){
                    q.add(new int[]{i,j});
                    dist[i][j]=0;
                }
            }
        }
        //多源bfs
        while(!q.isEmpty()){
            int[] t =q.poll();
            int a=t[0],b=t[1];
            for(int i=0;i<4;i++){
                int x=a+dx[i],y=b+dy[i];
                if(x>=0 && x<m && y>=0 && y<n && dist[x][y]==-1){
                    dist[x][y]=dist[a][b]+1;//从a,b的位置扩展到x,y的
                    q.add(new int[]{x,y});
                }
            }
        }
        return dist;
    }
}
